////////////////////////////////////////////////////////////////////////////////
//
//	Original file Name: Player.java
//	Originating Author: JWhitefield
//	
//	Description:
//
////////////////////////////////////////////////////////////////////////////////

package com.jjw.game.world.entity.character;

import com.jjw.game.graphics.Sprite;
import com.jjw.game.input.IInputPlayer;
import com.jjw.game.screen.Screen;
import com.jjw.game.world.tile.TileManager;

public class Player extends Mob {
	//--------------------------------------------------------------------------
	//
	//Properties
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
	
	//----------------------------------
	//  Getters / Setters
	//----------------------------------
	
	//----------------------------------
	// Private
	//----------------------------------

	private IInputPlayer playerInputDevice; 
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
	
	public Player( IInputPlayer inputDevice ) {
		
		this.playerInputDevice = inputDevice;
	}
	
	public void render( Screen screen){

		if( temp == null )
			temp = TileManager.createTile("0").getCurrentSprite();
		
		screen.render(this.getX(), this.getY(), temp);
	}

	
	//----------------------------------
	// Private
	//----------------------------------
	
	/**
	 * Handles the user input from the player
	 */
	private void handlePlayerUserInput(){
		
		//Movement variables so we can find out if the player has moved or not 
		int xa = 0;
		int ya = 0;
		
		//Check the move up input
		if(playerInputDevice.getUpInputButton().isDown()){
			ya -= 2;
		}
		//Check the move down input
		if(playerInputDevice.getDownInputButton().isDown()){
			ya += 2;
		}
		//Check the move left input 
		if(playerInputDevice.getLeftInputButton().isDown()){
			xa -= 2;
		}
		//Check the move right input 
		if(playerInputDevice.getRightInputButton().isDown()){
			xa += 2;
		}
				
		//Now move the player
		this.move(xa, ya);
	}
	
	//----------------------------------
	// Overriden / Implmented
	//----------------------------------
	
	private Sprite temp;
		
	@Override
	public void tick(){
		super.tick();
		
		//Handle any user input 
		this.handlePlayerUserInput();
	}
	
}
